package com.panasonic.cn.cmsc;

import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;
import java.sql.SQLException;
import com.fujitsu.fks.jaaf.core.*;

public class SQLMUSR02{
	private Hashtable paramsString     = new Hashtable();
	private Hashtable paramsBigDecimal = new Hashtable();
	private Hashtable paramsFree       = new Hashtable();
	private String lastSql_ = null;

	private String getString(String name){
		if(name==null) return "";
		String returnStr = (String)paramsString.get(name);
		if(returnStr==null) return "";
		return "'"+FrameworkCommon.stringReplaceSQuote(returnStr)+"'";
	}

	private String getBigDecimal(String name){
		if(name==null) return "";
		BigDecimal returnStr = (BigDecimal)paramsBigDecimal.get(name);
		if(returnStr==null) return "";
		return returnStr.toString();
	}

	private String getFree(String name){
		if(name==null) return "";
		String returnStr = (String)paramsFree.get(name);
		if(returnStr==null) return "";
		return returnStr;
	}

	public String getLastSql(){
		return lastSql_;
	}

	public SelectResultRset SELECT_USR01(FrameworkDbCommon db) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT ");
		sql.append("NVL( USR.USER_ID,'') AS USER_ID,");
		sql.append("NVL( USR.USER_NAME,'') AS USER_NAME,");
		sql.append("NVL( USR.PASSWORD,'') AS PASSWORD,");
		sql.append("NVL( USR.CTRL_DVSN_CD,'') AS CTRL_DVSN_CD,");
		sql.append("NVL( USR.AUTH_LEVEL,'') AS AUTH_LEVEL,");
		sql.append("NVL( USR.BSNS_TYP,'') AS BSNS_TYP,");
		sql.append("NVL( USR.MAIL_ADDRESS,'') AS MAIL_ADDRESS,");
		sql.append("NVL( USR.MAIL_SIZE,'') AS MAIL_SIZE,");
		sql.append("NVL( USR.L_DSP_NO,'') AS L_DSP_NO,");
		sql.append("NVL( USR.MENU_TYP,'') AS MENU_TYP,");
		sql.append("NVL( USR.PSW_TEST,'') AS PSW_TEST,");
		sql.append("NVL( USR.USER_AB_ID,'') AS USER_AB_ID,");
		sql.append("TO_CHAR(NVL( USR.RGS_DTTM,''),'YYYYMMDDHH24MISS') AS RGS_DTTM,");
		sql.append("NVL( USR.RGS_CHRG_CD,'') AS RGS_CHRG_CD,");
		sql.append("NVL( USR.RGS_PGID,'') AS RGS_PGID,");
		sql.append("TO_CHAR(NVL( USR.UPD_DTTM,''),'YYYYMMDDHH24MISS') AS UPD_DTTM,");
		sql.append("TO_CHAR(NVL( USR.PSW_CHANGE_DTTM,''),'YYYYMMDD') AS PSW_CHANGE_DTTM,");
		sql.append("NVL( USR.UPD_CHRG_CD,'') AS UPD_CHRG_CD,");
		sql.append("NVL( USR.UPD_PGID,'') AS UPD_PGID,");
		sql.append("M01.TRPT_NM_CN ");
		sql.append("FROM USR,M01  ");
		sql.append("WHERE USR.CTRL_DVSN_CD = M01.VDR_CD ");
		sql.append("AND M01.APL_BDT <"+((getString("SYSDATE").equals(""))?" is null ":"=")+getString("SYSDATE")+" ");
		sql.append("AND M01.APL_EDT >"+((getString("SYSDATE").equals(""))?" is null ":"=")+getString("SYSDATE")+" ");
		sql.append("ORDER BY USER_ID,CTRL_DVSN_CD ");
		db.setSql(sql.toString());
		lastSql_ =sql.toString();
		SelectResultRset srr = db.executeQuery();
		paramsString     = new Hashtable();
		paramsBigDecimal = new Hashtable();
		paramsFree       = new Hashtable();

		return srr;
	}

	public SelectResultRset SELECT_USR02(FrameworkDbCommon db) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT DISTINCT ");
		sql.append("NVL( USR.USER_ID,'') AS USER_ID,");
		sql.append("NVL( USR.USER_NAME,'') AS USER_NAME,");
		sql.append("NVL( USR.PASSWORD,'') AS PASSWORD,");
		sql.append("NVL( USR.CTRL_DVSN_CD,'') AS CTRL_DVSN_CD,");
		sql.append("NVL( USR.AUTH_LEVEL,'') AS AUTH_LEVEL,");
		sql.append("NVL( USR.BSNS_TYP,'') AS BSNS_TYP,");
		sql.append("NVL( USR.MAIL_ADDRESS,'') AS MAIL_ADDRESS,");
		sql.append("NVL( USR.MAIL_SIZE,'') AS MAIL_SIZE,");
		sql.append("NVL( USR.L_DSP_NO,'') AS L_DSP_NO,");
		sql.append("NVL( USR.MENU_TYP,'') AS MENU_TYP,");
		sql.append("NVL( USR.PSW_TEST,'') AS PSW_TEST,");
		sql.append("NVL( USR.USER_AB_ID,'') AS USER_AB_ID,");
		sql.append("TO_CHAR(NVL( USR.RGS_DTTM,''),'YYYYMMDDHH24MISS') AS RGS_DTTM,");
		sql.append("NVL( USR.RGS_CHRG_CD,'') AS RGS_CHRG_CD,");
		sql.append("NVL( USR.RGS_PGID,'') AS RGS_PGID,");
		sql.append("TO_CHAR(NVL( USR.UPD_DTTM,''),'YYYYMMDDHH24MISS') AS UPD_DTTM,");
		sql.append("TO_CHAR(NVL( USR.PSW_CHANGE_DTTM,''),'YYYYMMDD') AS PSW_CHANGE_DTTM,");
		sql.append("NVL( USR.UPD_CHRG_CD,'') AS UPD_CHRG_CD,");
		sql.append("NVL( USR.UPD_PGID,'') AS UPD_PGID,");
		sql.append("M01.TRPT_NM_CN ");
		sql.append("FROM USR,M01  ");
		sql.append("WHERE USR.USER_ID LIKE "+getString("USER_ID")+" ");
		sql.append("AND USR.CTRL_DVSN_CD = M01.VDR_CD ");
		sql.append("AND M01.APL_BDT <"+((getString("SYSDATE").equals(""))?" is null ":"=")+getString("SYSDATE")+" ");
		sql.append("AND M01.APL_EDT >"+((getString("SYSDATE").equals(""))?" is null ":"=")+getString("SYSDATE")+" ");
		sql.append("ORDER BY USER_ID,CTRL_DVSN_CD");
		db.setSql(sql.toString());
		lastSql_ =sql.toString();
		SelectResultRset srr = db.executeQuery();
		paramsString     = new Hashtable();
		paramsBigDecimal = new Hashtable();
		paramsFree       = new Hashtable();

		return srr;
	}


	public void setSYSDATE(String value){
		if(value==null) {
			paramsString.remove("SYSDATE");
			return;
		}
		paramsString.put("SYSDATE",value);
	}


	public void setUSER_ID(String value){
		if(value==null) {
			paramsString.remove("USER_ID");
			return;
		}
		paramsString.put("USER_ID",value);
	}


}
